package persistence.xstream;

import persistence.CorruptDataException ;
import persistence.PersistenceFactory ;
import persistence.PersistenceController ;

/**
 * @author idan
 *
 */
public class XStreamPersistenceFactory implements PersistenceFactory
{

	private boolean loadOnStartup ;
	private XmlDatabaseFileList fileList ;

	/**
	 * @param loadOnStartup whether to load elements on startup or start a fresh database.
	 * @param fileList files used by the database.
	 */
	public XStreamPersistenceFactory(final boolean loadOnStartup, final XmlDatabaseFileList fileList)
	{
		super() ;
		this.loadOnStartup = loadOnStartup ;
		this.fileList = fileList ;
	}


	/**
	 * @see persistence.PersistenceFactory#loadingFromExisting()
	 */
	@Override
	public boolean loadingFromExisting()
	{
		return this.loadOnStartup ;
	}

	/**
	 * @see persistence.PersistenceFactory#newDirecoryPersistence()
	 */
	@Override
	public PersistenceController newDirecoryPersistence() throws CorruptDataException
	{
		return new XStreamPersistenceController(this.fileList.getDirectoryFile(), this.loadOnStartup) ;
	}

	/**
	 * @see persistence.PersistenceFactory#newLoginPersistence()
	 */
	@Override
	public PersistenceController newLoginPersistence() throws CorruptDataException
	{
		return new XStreamPersistenceController(this.fileList.getLoginFile(), this.loadOnStartup) ;
	}

	/**
	 * @see persistence.PersistenceFactory#newMemberPersistence()
	 */
	@Override
	public PersistenceController newMemberPersistence() throws CorruptDataException
	{
		return new XStreamPersistenceController(this.fileList.getMemberFile(), this.loadOnStartup) ;
	}


	/**
	 * @see persistence.PersistenceFactory#newPostPersistence()
	 */
	@Override
	public PersistenceController newPostPersistence() throws CorruptDataException
	{
		return new XStreamPersistenceController(this.fileList.getPostFile(), this.loadOnStartup) ;

	}


	/**
	 * @see persistence.PersistenceFactory#newThreadPersistence()
	 */
	@Override
	public PersistenceController newThreadPersistence() throws CorruptDataException
	{
		return new XStreamPersistenceController(this.fileList.getThreadFile(), this.loadOnStartup) ;

	}

}
